<?php

namespace common\models\datas;

use frontend\models\datas\ClassManage;
use Yii;
use yii\helpers\Html;

/**
 * This is the model class for table "{{%admissionfee}}".
 *
 * @property integer $id
 * @property integer $customer_id
 * @property integer $student_id
 * @property integer $mechanic_id
 * @property integer $class_id
 * @property integer $class_student_id
 * @property integer $goods_id
 * @property integer $site_id
 * @property integer $status
 * @property integer $created_at
 * @property integer $mechanic_name
 * @property integer $goods_name
 * @property integer $admissionfee
 * @property integer $classroom_id
 * @property integer $classroom_name
 * @property integer $teacher_id
 * @property integer $teacher_name
 * @property integer $class_date
 * @property integer $class_start
 * @property integer $class_end
 * @property integer $customer_name
 * @property integer $student_name
 * @property integer $class_day
 * @property integer $lesson_num
 * @property integer $return_cash
 * @property integer $actual_cost
 */
class Admissionfee extends \common\components\bases\BaseModel
{
    /**
     * @inheritdoc
     */
    public $lesson_num;//课时数
    public $return_cash;//课时返现金额
    public $actual_cost;//实际招生费(合计)

    public static function tableName()
    {
        return '{{%admissionfee}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['customer_id', 'student_id', 'mechanic_id', 'class_id', 'class_student_id', 'goods_id', 'site_id', 'status', 'created_at'], 'integer']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('common', '自增id'),
            'customer_id' => Yii::t('common', '会员id'),
            'student_id' => Yii::t('common', '学生id'),
            'mechanic_id' => Yii::t('common', '机构id'),
            'class_id' => Yii::t('common', '班级id'),
            'class_student_id' => Yii::t('common', '班级学生id'),
            'goods_id' => Yii::t('common', '商品id'),
            'site_id' => Yii::t('common', '广场id'),
            'status' => Yii::t('common', '状态 是否结算（0否 1 是）'),
            'created_at' => Yii::t('common', '创建时间'),
            'machanic_name' => Yii::t('common', '机构名称'),
            'goods_name' => Yii::t('common', '课程名称'),
            'cost' => Yii::t('common', '总成本价'),
            'classroom_id' => Yii::t('common', '教室id'),
            'classroom_name' => Yii::t('common', '教室姓名'),
            'teacher_id' => Yii::t('common', '老师id'),
            'teacher_name' => Yii::t('common', '老师姓名'),
            'class_date' => Yii::t('common', '上课日期'),
            'class_day' => Yii::t('common', '上课星期'),
            'class_start' => Yii::t('common', '上课开始时间'),
            'class_end' => Yii::t('common', '上课结束时间'),
            'customer_name' => Yii::t('common', '会员姓名'),
            'student_name' => Yii::t('common', '学生姓名'),
            'lesson_num' => Yii::t('common', '课时数'),
            'return_cash' => Yii::t('common', '课时返现金额'),
            'actual_cost' => Yii::t('common', '实际招生费(合计)'),
        ];
    }

    public function fields()
    {
        $fields = parent::fields();
        $fields['status'] = function () {
            switch ($this->status) {
                case 0:
                    return \Yii::t('frontend', "未结算");
                case 1:
                    return \Yii::t('frontend', "已结算");
            }
        };
        $fields['created_at'] = function(){
            return \Yii::$app->formatter->asDatetime($this->created_at);
        };
        return $fields;
    }

    public function extraFields(){
        return [
            'checkbox'=> function(){
                $disabled = false;
                if($this->status == 1){
                    $disabled = true;
                }
                return Html::checkbox('checkbox',false,['value'=>$this->id,'disabled'=>$disabled]);
            }
        ];
    }

    public function getClassmanage()
    {
        return $this->hasOne(ClassManage::className(), ['class_id' => 'class_id']);
    }


}
